<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <title th:text="${blog.title}">博客详情</title>
</head>
<body>
<!--<img class="ui fluid image m-background">-->
<!--导航-->
<nav id="top" th:replace="_fragments :: menu(1)">
</nav>

<!--    中间内容-->
<div class="m-padded-tb-large m-opacity-mini m-container-small animate__animated animate__fadeInUp animate_fast">
    <div class="ui container m-shadow-small">
        <!--        头部-->
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="https://unsplash.it/110/110?image=1004" th:src="@{${blog.user.avatar}}" alt=""
                         class="ui avatar image">
                    <div class="content">
                        <div class="header" th:text="${blog.user.nickname}"><a href="#">南望96X</a></div>
                    </div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2020-10-1</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i><span th:text="${blog.views}">2342</span>
                </div>
            </div>
        </div>
        <!--        图片区域-->
        <div class="ui attached segment">
            <img src="https://unsplash.it/800/450?image=1005" th:src="@{${blog.firstPicture}}" alt=""
                 class="ui rounded fluid image">
        </div>
        <!--        内容区域-->
        <div class="ui attached segment">
            <div class="ui right aligned basic container">
                <div class="ui orange basic label" th:text="${blog.flag}">原创</div>
            </div>

            <h2 class="ui center aligned header" th:text="${blog.title}">Java集合类学习笔记1-------集合类概述</h2>
            <div id="content" class="typo js-toc-content  typo-selection m-padded-lr-responsive m-padded-tb-big"
                 th:utext="${blog.content}">
            </div>

            <!--            标签-->
            <div class="m-padded-lr-responsive">
                <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">学习笔记
                </div>
            </div>

            <!--            赞赏-->
            <!--            <div class="ui center aligned basic segment">-->
            <!--                <button class="ui orange basic circular button">-->
            <!--                    赞赏-->
            <!--                </button>-->
            <!--            </div>-->
        </div>
        <!--        博客信息-->
        <div class="ui attached positive message m-padded-tb-big">
            <ui class="center aligned list">
                <li>作者：<span th:text="${blog.user.nickname}">南望96X</span></li>
                <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2020-10-9 12：12</span>
                </li>
                <li>版权声明：自由转载-非商用-非衍生-保持署名</li>
            </ui>
        </div>
        <!--        留言区域-->
        <div class="ui bottom attached segment">
            <!--            留言区域列表-->
            <div id="comment-container" class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments">
                        <h3 class="ui dividing header" style="max-width: 100%;">Comments</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Matt</span>
                                    <div class="ui basic teal left pointing label m-padded-mini"
                                         th:if="${comment.adminComment}">博主
                                    </div>
                                </a>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                </div>
                                <div class="text" th:text="${comment.content}">太赞了！</div>
                                <div class="actions">
                                    <a data-commentid="1" data-commentnickname="Matt" onclick="reply(this)"
                                       th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                                       class="reply">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">Matt</span>
                                            <div class="ui basic teal left pointing label m-padded-mini"
                                                 th:if="${reply.adminComment}">博主
                                            </div>
                                            &nbsp;<span th:text="|@ ${reply.parentComment.nickname}|" class="m-teal">@David</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date"
                                                  th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">太赞了！</div>
                                        <div class="actions">
                                            <a data-commentid="1" data-commentnickname="Matt" onclick="reply(this)"
                                               th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}"
                                               class="reply">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--/*-->
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005">
                            </a>
                            <div class="content">
                                <a class="author">Elliot Fu</a>
                                <div class="metadata">
                                    <span class="date">昨天上午12:30</span>
                                </div>
                                <div class="text">
                                    <p>這對我的研究是非常有用.謝謝!</p>
                                </div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                            <div class="comments">
                                <div class="comment">
                                    <a class="avatar">
                                        <img src="https://unsplash.it/100/100?image=1005">
                                    </a>
                                    <div class="content">
                                        <a class="author">Jenny Hess</a>
                                        <div class="metadata">
                                            <span class="date">刚刚</span>
                                        </div>
                                        <div class="text">艾略特你永远是多么正确 :)</div>
                                        <div class="actions">
                                            <a class="reply">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005">
                            </a>
                            <div class="content">
                                <a class="author">Joe Henderson</a>
                                <div class="metadata">
                                    <span class="date">5 天以前</span>
                                </div>
                                <div class="text">老兄，这太棒了。非常感谢。</div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                        </div>
                        <!--*/-->
                    </div>
                </div>
            </div>
            <!--            回复框区域-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea style="margin-top: 20px !important;" name="content" placeholder="请输入评论信息"></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user}!=null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <button id="commentpost-btn" type="submit" class="ui teal button m-mobile-wide">
                            <i class="edit icon"></i>
                            发布
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--小菜单-->
<div class="m-padded-big m-fixed m-right-bottom">
    <div class="ui vertical icon buttons">
        <button type="button" class="ui toc violet button">目录</button>
        <a href="#comment-container" type="button" class="ui violet button">留言</a>
        <div id="toTop-button" type="button" class="ui button">
            <i class="chevron up icon"></i>
        </div>
    </div>
</div>

<!--弹出目录-->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px">
    <ol class="js-toc">

    </ol>
</div>
<!--    底部-->
<footer th:replace="_fragments :: footer">
</footer>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="../static/lib/toc/tocbot.min.js" th:src="@{/lib/toc/tocbot.min.js}"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-scrollTo/2.1.2/jquery.scrollTo.min.js"></script>
<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });

    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500);

    });

    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入您的昵称'
                }]
            }
        }
    })

    //前端地址写成/*[[@{/comments}]]*/"/comments"
    function postData() {
        $("#comment-container").load("/comments", {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "content": $("[name='content']").val()
        }, function (responseTxt, statusTxt, xhr) {
//        $(window).scrollTo($('#comment-container'),500);
            clearContent();
        });
    }

    $('#commentpost-btn').click(function () {
        const boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('校验成功');
            postData();
        } else {
            console.log('校验失败');
        }
    });

    $(function () {
        console.log('执行');
        $("#comment-container").load("[[@{/comments/{id}(id=${blog.id})}]]");
    });

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论内容");
        // location.reload();
    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);

    }

</script>
<script type="text/javascript" color="0,0,255" opacity='1' zIndex="-1" count="150"
        src="//cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js"></script>
<th:block th:replace="_fragments :: script"></th:block>

</body>
</html>
